home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gdevprn.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  26.8 KB  |  669 lines

  1. /* Copyright (C) 1989, 1995, 1996, 1997, 1998, 1999, 2000 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gdevprn.h,v 1.6 2000/09/19 19:00:21 lpd Exp $ */
  20. /* Common header file for memory-buffered printers */
  21.  
  22. #ifndef gdevprn_INCLUDED
  23. #  define gdevprn_INCLUDED
  24.  
  25. #include "memory_.h"
  26. #include "string_.h"
  27. #include "gx.h"
  28. #include "gp.h"            /* for gp_file_name_sizeof */
  29. #include "gserrors.h"
  30. #include "gsmatrix.h"        /* for gxdevice.h */
  31. #include "gsutil.h"        /* for memflip8x8 */
  32. #include "gxdevice.h"
  33. #include "gxdevmem.h"
  34. #include "gxclist.h"
  35. #include "gxrplane.h"
  36. #include "gsparam.h"
  37.  
  38. /*
  39.  * Define the parameters for the printer rendering method.
  40.  * If the entire bitmap fits in PRN_MAX_BITMAP, and there is at least
  41.  * PRN_MIN_MEMORY_LEFT memory left after allocating it, render in RAM,
  42.  * otherwise use a command list with a size of PRN_BUFFER_SPACE.
  43.  * (These are parameters that can be changed by a client program.)
  44.  */
  45. /* Define parameters for machines with little dinky RAMs.... */
  46. #define PRN_MAX_BITMAP_SMALL 32000
  47. #define PRN_BUFFER_SPACE_SMALL 25000
  48. #define PRN_MIN_MEMORY_LEFT_SMALL 32000
  49. /* Define parameters for machines with great big hulking RAMs.... */
  50. #define PRN_MAX_BITMAP_LARGE 10000000L
  51. #define PRN_BUFFER_SPACE_LARGE 4000000L
  52. #define PRN_MIN_MEMORY_LEFT_LARGE 500000L
  53. /* Define parameters valid on all machines. */
  54. #define PRN_MIN_BUFFER_SPACE 10000    /* give up if less than this */
  55. /* Now define conditional parameters. */
  56. #if arch_small_memory
  57. #  define PRN_MAX_BITMAP PRN_MAX_BITMAP_SMALL
  58. #  define PRN_BUFFER_SPACE PRN_BUFFER_SPACE_SMALL
  59. #  define PRN_MIN_MEMORY_LEFT PRN_MIN_MEMORY_LEFT_SMALL
  60. #else
  61. /****** These should really be conditional on gs_debug_c('.') if
  62.  ****** DEBUG is defined, but they're used in static initializers,
  63.  ****** so we can't do it.
  64.  ******/
  65. #  if 0                /****** #  ifdef DEBUG ***** */
  66. #    define PRN_MAX_BITMAP\
  67.        (gs_debug_c('.') ? PRN_MAX_BITMAP_SMALL : PRN_MAX_BITMAP_LARGE)
  68. #    define PRN_BUFFER_SPACE\
  69.        (gs_debug_c('.') ? PRN_BUFFER_SPACE_SMALL : PRN_BUFFER_SPACE_LARGE)
  70. #    define PRN_MIN_MEMORY_LEFT\
  71.        (gs_debug_c('.') ? PRN_MIN_MEMORY_LEFT_SMALL : PRN_MIN_MEMORY_LEFT_LARGE)
  72. #  else
  73. #    define PRN_MAX_BITMAP PRN_MAX_BITMAP_LARGE
  74. #    define PRN_BUFFER_SPACE PRN_BUFFER_SPACE_LARGE
  75. #    define PRN_MIN_MEMORY_LEFT PRN_MIN_MEMORY_LEFT_LARGE
  76. #  endif
  77. #endif
  78.  
  79. /* Define the abstract type for a printer device. */
  80. #ifndef gx_device_printer_DEFINED
  81. #  define gx_device_printer_DEFINED
  82. typedef struct gx_device_printer_s gx_device_printer;
  83. #endif
  84.  
  85. /* Define the abstract type for some band device procedures' arguments. */
  86. typedef struct gdev_prn_start_render_params_s gdev_prn_start_render_params;
  87.  
  88. /* Define the abstract type for a page queue for async rendering. */
  89. #ifndef gx_page_queue_DEFINED
  90. #  define gx_page_queue_DEFINED
  91. typedef struct gx_page_queue_s gx_page_queue_t;
  92. #endif
  93.  
  94. /* Define the abstract type for parameters describing buffer space. */
  95. #ifndef gdev_prn_space_params_DEFINED
  96. #  define gdev_prn_space_params_DEFINED
  97. typedef struct gdev_prn_space_params_s gdev_prn_space_params;
  98. #endif
  99.  
  100. /*
  101.  * Define the special procedures for band devices.
  102.  */
  103. typedef struct gx_printer_device_procs_s {
  104.  
  105.     /*
  106.      * Print the page on the output file.  Required only for devices
  107.      * where output_page is gdev_prn_output_page; ignored for other
  108.      * devices.
  109.      */
  110.  
  111. #define prn_dev_proc_print_page(proc)\
  112.   int proc(P2(gx_device_printer *, FILE *))
  113.     prn_dev_proc_print_page((*print_page));
  114. /* BACKWARD COMPATIBILITY */
  115. #define dev_proc_print_page(proc) prn_dev_proc_print_page(proc)
  116.  
  117.     /* Print the page on the output file, with a given # of copies. */
  118.  
  119. #define prn_dev_proc_print_page_copies(proc)\
  120.   int proc(P3(gx_device_printer *, FILE *, int))
  121.     prn_dev_proc_print_page_copies((*print_page_copies));
  122. /* BACKWARD COMPATIBILITY */
  123. #define dev_proc_print_page_copies(proc) prn_dev_proc_print_page_copies(proc)
  124.  
  125.     /*
  126.      * Define buffer device management procedures.
  127.      * See gxdevcli.h for the definitions.
  128.      */
  129.  
  130.     gx_device_buf_procs_t buf_procs;
  131.  
  132.     /*
  133.      * Compute effective space params. These results effectively override
  134.      * the space_params in the device, but does not replace them; that is to
  135.      * say that computed space params are temps used for computation.
  136.      * Procedure must fill in only those space_params that it wishes to
  137.      * override, using curr width, height, margins, etc.
  138.      *
  139.      * Caller is gdevprn.open & gdevprn.put_params, calls driver or
  140.      * default.
  141.      */
  142.  
  143. #define prn_dev_proc_get_space_params(proc)\
  144.   void proc(P2(const gx_device_printer *, gdev_prn_space_params *))
  145.     prn_dev_proc_get_space_params((*get_space_params));
  146.  
  147.     /*
  148.      * Only for gx_device_printer devices that overlap interpreting and
  149.      * rasterizing. Since there are 2 instances of the device (1 for writing
  150.      * the cmd list & 1 for rasterizing it), and each device is associated
  151.      * with an different thread, this function is called to start the
  152.      * rasterizer's thread. Once started, the rasterizer thread must call
  153.      * down to gdev_prn_asnyc_render_thread, which will only return after
  154.      * device closes.
  155.      *
  156.      * Caller is gdevprna.open, calls driver implementation or default.
  157.      */
  158.  
  159. #define prn_dev_proc_start_render_thread(proc)\
  160.   int proc(P1(gdev_prn_start_render_params *))
  161.     prn_dev_proc_start_render_thread((*start_render_thread));
  162.  
  163.     /*
  164.      * Only for gx_device_printer devices that overlap interpreting and
  165.      * rasterizing. Since there are 2 instances of the device (1 for writing
  166.      * the cmd list & 1 for rasterizing it), these fns are called to
  167.      * open/close the rasterizer's instance, once the writer's instance has
  168.      * been created & init'd. These procs must cascade down to
  169.      * gdev_prn_async_render_open/close.
  170.      *
  171.      * Caller is gdevprna, calls driver implementation or default.
  172.      */
  173.  
  174. #define prn_dev_proc_open_render_device(proc)\
  175.   int proc(P1(gx_device_printer *))
  176.     prn_dev_proc_open_render_device((*open_render_device));
  177.  
  178. #define prn_dev_proc_close_render_device(proc)\
  179.   int proc(P1(gx_device_printer *))
  180.     prn_dev_proc_close_render_device((*close_render_device));
  181.  
  182.     /*
  183.      * Buffer a page on the output device. A page may or may not have been
  184.      * fully rendered, but the rasterizer needs to realize the page to free
  185.      * up resources or support copypage. Printing a page may involve zero or
  186.      * more buffer_pages. All buffer_page output is overlaid in the buffer
  187.      * until a terminating print_page or print_page_copies clears the
  188.      * buffer. Note that, after the first buffer_page, the driver must call
  189.      * the lower-level gdev_prn_render_lines procedure instead of
  190.      * get_bits. The difference is that gdev_prn_render_lines requires the
  191.      * caller to supply the same buffered bitmap that was computed as a
  192.      * result of a previous buffer_page, so that gdev_prn_render_lines can
  193.      * add further marks to the existing buffered image. NB that output must
  194.      * be accumulated in buffer even if num_copies == 0.
  195.      *
  196.      * Caller is expected to be gdevprn, calls driver implementation or
  197.      * default.  */
  198.  
  199. #define prn_dev_proc_buffer_page(proc)\
  200.   int proc(P3(gx_device_printer *, FILE *, int))
  201.     prn_dev_proc_buffer_page((*buffer_page));
  202.  
  203. } gx_printer_device_procs;
  204.  
  205. /* ------ Printer device definition ------ */
  206.  
  207. /* Structure for generic printer devices. */
  208. /* This must be preceded by gx_device_common. */
  209. /* Printer devices are actually a union of a memory device */
  210. /* and a clist device, plus some additional state. */
  211. #define prn_fname_sizeof gp_file_name_sizeof
  212. typedef enum {
  213.     BandingAuto = 0,
  214.     BandingAlways,
  215.     BandingNever
  216. } gdev_prn_banding_type;
  217. struct gdev_prn_space_params_s {
  218.     long MaxBitmap;        /* max size of non-buffered bitmap */
  219.     long BufferSpace;        /* space to use for buffer */
  220.     gx_band_params_t band;    /* see gxclist.h */
  221.     bool params_are_read_only;    /* true if put_params may not modify this struct */
  222.     gdev_prn_banding_type banding_type;    /* used to force banding or bitmap */
  223. };
  224.  
  225. #define gx_prn_device_common\
  226.     byte skip[max(sizeof(gx_device_memory), sizeof(gx_device_clist)) -\
  227.           sizeof(gx_device) + sizeof(double) /* padding */];\
  228.     gx_printer_device_procs printer_procs;\
  229.         /* ------ Device parameters that must be set ------ */\
  230.         /* ------ before calling the device open routine. ------ */\
  231.     gdev_prn_space_params space_params;\
  232.     char fname[prn_fname_sizeof];    /* OutputFile */\
  233.         /* ------ Other device parameters ------ */\
  234.     bool OpenOutputFile;\
  235.     bool ReopenPerPage;\
  236.     bool Duplex;\
  237.       int Duplex_set;        /* -1 = not supported */\
  238.         /* ------ End of parameters ------ */\
  239.     bool file_is_new;        /* true iff file just opened */\
  240.     FILE *file;            /* output file */\
  241.     long buffer_space;    /* amount of space for clist buffer, */\
  242.                     /* 0 means not using clist */\
  243.     byte *buf;            /* buffer for rendering */\
  244.         /* ---- Begin async rendering support --- */\
  245.     gs_memory_t *buffer_memory;    /* allocator for command list */\
  246.     gs_memory_t *bandlist_memory;    /* allocator for bandlist files */\
  247.     proc_free_up_bandlist_memory((*free_up_bandlist_memory));      /* if nz, proc to free some bandlist memory */\
  248.     gx_page_queue_t *page_queue;    /* if <> 0,page queue for gdevprna NOT GC'd */\
  249.     bool is_async_renderer;        /* device is only the rendering part of async device */\
  250.     gx_device_printer *async_renderer;    /* in async writer, pointer to async renderer */\
  251.     uint clist_disable_mask;    /* mask of clist options to disable */\
  252.         /* ---- End async rendering support --- */\
  253.     gx_device_procs orig_procs    /* original (std_)procs */
  254.  
  255. /* The device descriptor */
  256. struct gx_device_printer_s {
  257.     gx_device_common;
  258.     gx_prn_device_common;
  259. };
  260.  
  261. extern_st(st_device_printer);
  262. #define public_st_device_printer()    /* in gdevprn.c */\
  263.   gs_public_st_complex_only(st_device_printer, gx_device_printer,\
  264.     "gx_device_printer", 0, device_printer_enum_ptrs,\
  265.     device_printer_reloc_ptrs, gx_device_finalize)
  266.  
  267. /* Define a typedef for the sake of ansi2knr. */
  268. typedef dev_proc_print_page((*dev_proc_print_page_t));
  269.  
  270. /* Standard device procedures for printers */
  271. dev_proc_open_device(gdev_prn_open);
  272. dev_proc_output_page(gdev_prn_output_page);
  273. dev_proc_close_device(gdev_prn_close);
  274. #define gdev_prn_map_rgb_color gx_default_b_w_map_rgb_color
  275. #define gdev_prn_map_color_rgb gx_default_b_w_map_color_rgb
  276. dev_proc_get_params(gdev_prn_get_params);
  277. dev_proc_put_params(gdev_prn_put_params);
  278.  
  279. /* Default printer-specific procedures */
  280. /* VMS limits procedure names to 31 characters. */
  281. prn_dev_proc_get_space_params(gx_default_get_space_params);
  282. /* BACKWARD COMPATIBILITY */
  283. #define gdev_prn_default_get_space_params gx_default_get_space_params
  284. prn_dev_proc_start_render_thread(gx_default_start_render_thread); /* for async rendering only, see gdevprna.c */
  285. prn_dev_proc_open_render_device(gx_default_open_render_device);
  286. prn_dev_proc_close_render_device(gx_default_close_render_device);
  287. prn_dev_proc_buffer_page(gx_default_buffer_page); /* returns an error */
  288.  
  289. /* Macro for generating procedure table */
  290. #define prn_procs(p_open, p_output_page, p_close)\
  291.   prn_color_procs(p_open, p_output_page, p_close, gdev_prn_map_rgb_color, gdev_prn_map_color_rgb)
  292. #define prn_params_procs(p_open, p_output_page, p_close, p_get_params, p_put_params)\
  293.   prn_color_params_procs(p_open, p_output_page, p_close, gdev_prn_map_rgb_color, gdev_prn_map_color_rgb, p_get_params, p_put_params)
  294. #define prn_color_procs(p_open, p_output_page, p_close, p_map_rgb_color, p_map_color_rgb)\
  295.   prn_color_params_procs(p_open, p_output_page, p_close, p_map_rgb_color, p_map_color_rgb, gdev_prn_get_params, gdev_prn_put_params)
  296. /* See gdev_prn_open for explanation of the NULLs below. */
  297. #define prn_color_params_procs(p_open, p_output_page, p_close, p_map_rgb_color, p_map_color_rgb, p_get_params, p_put_params) {\
  298.     p_open,\
  299.     NULL,    /* get_initial_matrix */\
  300.     NULL,    /* sync_output */\
  301.     p_output_page,\
  302.     p_close,\
  303.     p_map_rgb_color,\
  304.     p_map_color_rgb,\
  305.     NULL,    /* fill_rectangle */\
  306.     NULL,    /* tile_rectangle */\
  307.     NULL,    /* copy_mono */\
  308.     NULL,    /* copy_color */\
  309.     NULL,    /* draw_line */\
  310.     NULL,    /* get_bits */\
  311.     p_get_params,\
  312.     p_put_params,\
  313.     NULL,    /* map_cmyk_color */\
  314.     NULL,    /* get_xfont_procs */\
  315.     NULL,    /* get_xfont_device */\
  316.     NULL,    /* map_rgb_alpha_color */\
  317.     gx_page_device_get_page_device,\
  318.     NULL,    /* get_alpha_bits */\
  319.     NULL,    /* copy_alpha */\
  320.     NULL,    /* get_band */\
  321.     NULL,    /* copy_rop */\
  322.     NULL,    /* fill_path */\
  323.     NULL,    /* stroke_path */\
  324.     NULL,    /* fill_mask */\
  325.     NULL,    /* fill_trapezoid */\
  326.     NULL,    /* fill_parallelogram */\
  327.     NULL,    /* fill_triangle */\
  328.     NULL,    /* draw_thin_line */\
  329.     NULL,    /* begin_image */\
  330.     NULL,    /* image_data */\
  331.     NULL,    /* end_image */\
  332.     NULL,    /* strip_tile_rectangle */\
  333.     NULL,    /* strip_copy_rop, */\
  334.     NULL,    /* get_clipping_box */\
  335.     NULL,    /* begin_typed_image */\
  336.     NULL,    /* map_color_rgb_alpha */\
  337.     NULL,    /* create_compositor */\
  338.     NULL,    /* get_hardware_params */\
  339.     NULL,    /* text_begin */\
  340.     NULL    /* finish_copydevice */\
  341. }
  342.  
  343. /* The standard printer device procedures */
  344. /* (using gdev_prn_open/output_page/close). */
  345. extern const gx_device_procs prn_std_procs;
  346.  
  347. /*
  348.  * Define macros for generating the device structure,
  349.  * analogous to the std_device_body macros in gxdevice.h
  350.  * Note that the macros are broken up so as to be usable for devices that
  351.  * add further initialized state to the printer device.
  352.  *
  353.  * The 'margin' values provided here specify the unimageable region
  354.  * around the edges of the page (in inches), and the left and top margins
  355.  * also specify the displacement of the device (0,0) point from the
  356.  * upper left corner.  We should provide macros that allow specifying
  357.  * all 6 values independently, but we don't yet.
  358.  *
  359.  * Note that print_page and print_page_copies must not both be defaulted.
  360.  */
  361. #define prn_device_body_rest2_(print_page, print_page_copies)\
  362.      { 0 },        /* std_procs */\
  363.      { 0 },        /* skip */\
  364.      { print_page,\
  365.        print_page_copies,\
  366.        { gx_default_create_buf_device,\
  367.          gx_default_size_buf_device,\
  368.          gx_default_setup_buf_device,\
  369.          gx_default_destroy_buf_device\
  370.        },\
  371.        gdev_prn_default_get_space_params,\
  372.        gx_default_start_render_thread,\
  373.        gx_default_open_render_device,\
  374.        gx_default_close_render_device,\
  375.        gx_default_buffer_page\
  376.      },\
  377.      { PRN_MAX_BITMAP, PRN_BUFFER_SPACE,\
  378.          { BAND_PARAMS_INITIAL_VALUES },\
  379.        0/*false*/,    /* params_are_read_only */\
  380.        BandingAuto    /* banding_type */\
  381.      },\
  382.      { 0 },        /* fname */\
  383.     0/*false*/,    /* OpenOutputFile */\
  384.     0/*false*/,    /* ReopenPerPage */\
  385.     0/*false*/, -1,    /* Duplex[_set] */\
  386.     0/*false*/, 0, 0, 0, /* file_is_new ... buf */\
  387.     0, 0, 0, 0, 0/*false*/, 0, 0, /* buffer_memory ... clist_dis'_mask */\
  388.     { 0 }    /* ... orig_procs */
  389. #define prn_device_body_rest_(print_page)\
  390.   prn_device_body_rest2_(print_page, gx_default_print_page_copies)
  391. #define prn_device_body_copies_rest_(print_page_copies)\
  392.   prn_device_body_rest2_(gx_print_page_single_copy, print_page_copies)
  393.  
  394. /* The Sun cc compiler won't allow \ within a macro argument list. */
  395. /* This accounts for the short parameter names here and below. */
  396. #define prn_device_margins_body(dtype, procs, dname, w10, h10, xdpi, ydpi, lo, to, lm, bm, rm, tm, ncomp, depth, mg, mc, dg, dc, print_page)\
  397.     std_device_full_body_type(dtype, &procs, dname, &st_device_printer,\
  398.       (int)((long)(w10) * (xdpi) / 10),\
  399.       (int)((long)(h10) * (ydpi) / 10),\
  400.       xdpi, ydpi,\
  401.       ncomp, depth, mg, mc, dg, dc,\
  402.       -(lo) * (xdpi), -(to) * (ydpi),\
  403.       (lm) * 72.0, (bm) * 72.0,\
  404.       (rm) * 72.0, (tm) * 72.0\
  405.     ),\
  406.     prn_device_body_rest_(print_page)
  407.  
  408. #define prn_device_body(dtype, procs, dname, w10, h10, xdpi, ydpi, lm, bm, rm, tm, ncomp, depth, mg, mc, dg, dc, print_page)\
  409.   prn_device_margins_body(dtype, procs, dname, w10, h10, xdpi, ydpi,\
  410.     lm, tm, lm, bm, rm, tm, ncomp, depth, mg, mc, dg, dc, print_page)
  411.  
  412. #define prn_device_std_margins_body(dtype, procs, dname, w10, h10, xdpi, ydpi, lo, to, lm, bm, rm, tm, color_bits, print_page)\
  413.     std_device_std_color_full_body_type(dtype, &procs, dname, &st_device_printer,\
  414.       (int)((long)(w10) * (xdpi) / 10),\
  415.       (int)((long)(h10) * (ydpi) / 10),\
  416.       xdpi, ydpi, color_bits,\
  417.       -(lo) * (xdpi), -(to) * (ydpi),\
  418.       (lm) * 72.0, (bm) * 72.0,\
  419.       (rm) * 72.0, (tm) * 72.0\
  420.     ),\
  421.     prn_device_body_rest_(print_page)
  422.  
  423. #define prn_device_std_body(dtype, procs, dname, w10, h10, xdpi, ydpi, lm, bm, rm, tm, color_bits, print_page)\
  424.   prn_device_std_margins_body(dtype, procs, dname, w10, h10, xdpi, ydpi,\
  425.     lm, tm, lm, bm, rm, tm, color_bits, print_page)
  426.  
  427. #define prn_device_std_margins_body_copies(dtype, procs, dname, w10, h10, xdpi, ydpi, lo, to, lm, bm, rm, tm, color_bits, print_page_copies)\
  428.     std_device_std_color_full_body_type(dtype, &procs, dname, &st_device_printer,\
  429.       (int)((long)(w10) * (xdpi) / 10),\
  430.       (int)((long)(h10) * (ydpi) / 10),\
  431.       xdpi, ydpi, color_bits,\
  432.       -(lo) * (xdpi), -(to) * (ydpi),\
  433.       (lm) * 72.0, (bm) * 72.0,\
  434.       (rm) * 72.0, (tm) * 72.0\
  435.     ),\
  436.     prn_device_body_copies_rest_(print_page_copies)
  437.  
  438. #define prn_device_std_body_copies(dtype, procs, dname, w10, h10, xdpi, ydpi, lm, bm, rm, tm, color_bits, print_page_copies)\
  439.   prn_device_std_margins_body_copies(dtype, procs, dname, w10, h10, xdpi, ydpi,\
  440.     lm, tm, lm, bm, rm, tm, color_bits, print_page_copies)
  441.  
  442.      /* Note that the following macros add { } around the data. */
  443.  
  444. #define prn_device_margins(procs, dname, w10, h10, xdpi, ydpi, lo, to, lm, bm, rm, tm, color_bits, print_page)\
  445. { prn_device_std_margins_body(gx_device_printer, procs, dname,\
  446.     w10, h10, xdpi, ydpi, lo, to, lm, bm, rm, tm, color_bits, print_page)\
  447. }
  448.  
  449. #define prn_device(procs, dname, w10, h10, xdpi, ydpi, lm, bm, rm, tm, color_bits, print_page)\
  450.   prn_device_margins(procs, dname, w10, h10, xdpi, ydpi,\
  451.     lm, tm, lm, bm, rm, tm, color_bits, print_page)
  452.  
  453. #define prn_device_margins_copies(procs, dname, w10, h10, xdpi, ydpi, lo, to, lm, bm, rm, tm, color_bits, print_page_copies)\
  454. { prn_device_std_margins_body_copies(gx_device_printer, procs, dname,\
  455.     w10, h10, xdpi, ydpi, lo, to, lm, bm, rm, tm, color_bits, print_page_copies)\
  456. }
  457.  
  458. #define prn_device_copies(procs, dname, w10, h10, xdpi, ydpi, lm, bm, rm, tm, color_bits, print_page_copies)\
  459.   prn_device_margins_copies(procs, dname, w10, h10, xdpi, ydpi,\
  460.     lm, tm, lm, bm, rm, tm, color_bits, print_page_copies)
  461.  
  462. /* ------ Utilities ------ */
  463. /* These are defined in gdevprn.c. */
  464.  
  465. /*
  466.  * Open the printer's output file if necessary.
  467.  */
  468. /* VMS limits procedure names to 31 characters. */
  469. int gdev_prn_open_printer_seekable(P3(gx_device *dev, bool binary_mode,
  470.                       bool seekable));
  471. /* BACKWARD COMPATIBILITY */
  472. #define gdev_prn_open_printer_positionable gdev_prn_open_printer_seekable
  473. /* open_printer defaults positionable = false */
  474. int gdev_prn_open_printer(P2(gx_device * dev, bool binary_mode));
  475. /*
  476.  * Test whether the printer's output file was just opened, i.e., whether
  477.  * this is the first page being written to this file.  This is only valid
  478.  * at the entry to a driver's print_page procedure.
  479.  */
  480. bool gdev_prn_file_is_new(P1(const gx_device_printer *pdev));
  481.  
  482. /*
  483.  * Determine the number of bytes required for one scan line of output to
  484.  * a printer device, without any padding.
  485.  */
  486. #define gdev_prn_raster(pdev) gx_device_raster((gx_device *)(pdev), 0)
  487.  
  488. /*
  489.  * Determine (conservatively) what colors are used in a given range of scan
  490.  * lines, and return the actual range of scan lines to which the result
  491.  * applies.  (Currently, the result will always actually apply to one or
  492.  * more full bands.)  In the non-banded case, this information is currently
  493.  * not available, so we return all-1s (i.e., any color may appear) as the
  494.  * 'or', and the entire page as the range; we may improve this someday.
  495.  *
  496.  * The return value is like get_band: the first Y value of the actual range
  497.  * is stored in *range_start, and the height of the range is returned.
  498.  * If the parameters are invalid, the procedure returns -1.
  499.  */
  500. int gdev_prn_colors_used(P5(gx_device *dev, int y, int height,
  501.                 gx_colors_used_t *colors_used,
  502.                 int *range_start));
  503. /*
  504.  * Determine the colors used in a saved page.  We still need the device
  505.  * in order to know the total page height.
  506.  */
  507. int gx_page_info_colors_used(P6(const gx_device *dev,
  508.                 const gx_band_page_info_t *page_info,
  509.                 int y, int height,
  510.                 gx_colors_used_t *colors_used,
  511.                 int *range_start));
  512.  
  513. /*
  514.  * Render a subrectangle of the page into a target device provided by the
  515.  * caller, optionally clearing the device before rendering.  The rectangle
  516.  * need not coincide exactly with band boundaries, but it will be most
  517.  * efficient if they do, since it is necessary to render every band that
  518.  * even partly falls within the rectangle.  This is the lowest-level
  519.  * rendering procedure: the other procedures for reading rasterized lines,
  520.  * defined below, ultimately call this one.
  521.  *
  522.  * render_plane is used only for internal cache bookkeeping: it doesn't
  523.  * affect what is passed to the buffer device.  It is the client's
  524.  * responsibility to set up a plane extraction device, if required, to
  525.  * select an individual plane for rendering.
  526.  *
  527.  * Note that it may be necessary to render more than one plane even if the
  528.  * caller only requests a single plane.  Currently this only occurs for
  529.  * non-trivial RasterOps on CMYK devices.  If this is the case, it is the
  530.  * client's responsibility to provide a target device that accumulates full
  531.  * pixels rather than a single plane: if the plane extraction device is
  532.  * asked to execute an operation that requires full pixels, it will return
  533.  * an error.
  534.  */
  535. int gdev_prn_render_rectangle(P5(gx_device_printer *pdev,
  536.                  const gs_int_rect *prect,
  537.                  gx_device *target,
  538.                  const gx_render_plane_t *render_plane,
  539.                  bool clear));
  540.  
  541. /*
  542.  * Read one or more rasterized scan lines for printing.
  543.  * The procedure either copies the scan lines into the buffer and
  544.  * sets *actual_buffer = buffer and *actual_bytes_per_line = bytes_per_line,
  545.  * or sets *actual_buffer and *actual_bytes_per_line to reference
  546.  * already-rasterized scan lines.
  547.  *
  548.  * For non-banded devices, copying is never necessary.  For banded devices,
  549.  * if the client's buffer is at least as large as the single preallocated
  550.  * one (if any), the band will be rasterized directly into the client's
  551.  * buffer, again avoiding copying.  Alternatively, if there is a
  552.  * preallocated buffer and the call asks for no more data than will fit
  553.  * in that buffer, buffer may be NULL: any necessary rasterizing will
  554.  * occur in the preallocated buffer, and a pointer into the buffer will be
  555.  * returned.
  556.  */
  557. int gdev_prn_get_lines(P8(gx_device_printer *pdev, int y, int height,
  558.               byte *buffer, uint bytes_per_line,
  559.               byte **actual_buffer, uint *actual_bytes_per_line,
  560.               const gx_render_plane_t *render_plane));
  561.  
  562. /*
  563.  * Read a rasterized scan line for sending to the printer.
  564.  * This is essentially a simplified form of gdev_prn_get_lines,
  565.  * except that it also calls gdev_prn_clear_trailing_bits.
  566.  */
  567. int gdev_prn_get_bits(P4(gx_device_printer *pdev, int y, byte *buffer,
  568.              byte **actual_buffer));
  569.  
  570. /*
  571.  * Copy scan lines to send to the printer.  This is now DEPRECATED,
  572.  * because it copies the data even if the data are already available in
  573.  * the right form in the rasterizer buffer.  Use gdev_prn_get_bits
  574.  * instead.  For documentation, see the implementation in gdevprn.c.
  575.  */
  576. int gdev_prn_copy_scan_lines(P4(gx_device_printer *, int, byte *, uint));
  577.  
  578. /*
  579.  * Clear any trailing bits in the last byte of one or more scan lines
  580.  * returned from the calls for reading out rasterized data.  Note that
  581.  * the device is only used to get the width and depth, and need not be
  582.  * a printer device.
  583.  */
  584. void gdev_prn_clear_trailing_bits(P4(byte *data, uint raster, int height,
  585.                      const gx_device *dev));
  586.  
  587. /*
  588.  * Close the printer's output file.
  589.  */
  590. int gdev_prn_close_printer(P1(gx_device *));
  591.  
  592. /* Print a single copy of a page by calling print_page_copies. */
  593. prn_dev_proc_print_page(gx_print_page_single_copy);
  594.  
  595. /*
  596.  * Define a default print_page_copies procedure just calls print_page
  597.  * the given number of times.
  598.  */
  599. prn_dev_proc_print_page_copies(gx_default_print_page_copies);
  600.  
  601. /*
  602.  * Determine the number of scan lines that should actually be passed
  603.  * to the device.
  604.  */
  605. int gdev_prn_print_scan_lines(P1(gx_device *));
  606.  
  607. /* Allocate / reallocate / free printer memory. */
  608. int gdev_prn_allocate_memory(P4(gx_device *pdev,
  609.                 gdev_prn_space_params *space,
  610.                 int new_width, int new_height));
  611. int gdev_prn_reallocate_memory(P4(gx_device *pdev,
  612.                   gdev_prn_space_params *space,
  613.                   int new_width, int new_height));
  614. int gdev_prn_free_memory(P1(gx_device *pdev));
  615.  
  616. /*
  617.  * Create the buffer device for a printer device.  Clients should always
  618.  * call this, and never call the device procedure directly.  The actual
  619.  * create_buf_device procedure is passed as an argument because the banding
  620.  * code needs this: normally it is dev_proc(some_dev, create_buf_device).
  621.  */
  622. typedef dev_proc_create_buf_device((*create_buf_device_proc_t));
  623. int gdev_create_buf_device(P6(create_buf_device_proc_t cbd_proc,
  624.                   gx_device **pbdev, gx_device *target,
  625.                   const gx_render_plane_t *render_plane,
  626.                   gs_memory_t *mem, bool for_band));
  627.  
  628. /* BACKWARD COMPATIBILITY */
  629. #define dev_print_scan_lines(dev)\
  630.   gdev_prn_print_scan_lines((gx_device *)(dev))
  631. #define gdev_mem_bytes_per_scan_line(dev)\
  632.   gdev_prn_raster((gx_device_printer *)(dev))
  633. #define gdev_prn_transpose_8x8(inp,ils,outp,ols)\
  634.   memflip8x8(inp,ils,outp,ols)
  635.  
  636. /* ------ Printer device types ------ */
  637. /**************** THE FOLLOWING CODE IS NOT USED YET. ****************/
  638.  
  639. #if 0                /**************** VMS linker gets upset *************** */
  640. #endif
  641. int gdev_prn_initialize(P3(gx_device *, const char *, dev_proc_print_page((*))));
  642. void gdev_prn_init_color(P4(gx_device *, int, dev_proc_map_rgb_color((*)), dev_proc_map_color_rgb((*))));
  643.  
  644. #define prn_device_type(dtname, initproc, pageproc)\
  645. private dev_proc_print_page(pageproc);\
  646. device_type(dtname, st_prn_device, initproc)
  647.  
  648. /****** FOLLOWING SHOULD CHECK __PROTOTYPES__ ******/
  649. #define prn_device_type_mono(dtname, dname, initproc, pageproc)\
  650. private dev_proc_print_page(pageproc);\
  651. private int \
  652. initproc(gx_device *dev)\
  653. {    return gdev_prn_initialize(dev, dname, pageproc);\
  654. }\
  655. device_type(dtname, st_prn_device, initproc)
  656.  
  657. /****** DITTO ******/
  658. #define prn_device_type_color(dtname, dname, depth, initproc, pageproc, rcproc, crproc)\
  659. private dev_proc_print_page(pageproc);\
  660. private int \
  661. initproc(gx_device *dev)\
  662. {    int code = gdev_prn_initialize(dev, dname, pageproc);\
  663.     gdev_prn_init_color(dev, depth, rcproc, crproc);\
  664.     return code;\
  665. }\
  666. device_type(dtname, st_prn_device, initproc)
  667.  
  668. #endif /* gdevprn_INCLUDED */
  669.